package com.mb.app.controller;

import com.mb.app.domain.TbCouponControl;
import com.mb.app.service.ITbCouponControlService;
import com.mb.common.controller.BaseController;
import com.mb.common.utils.PageUtils;
import com.mb.common.utils.Query;
import com.mb.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 优惠卷控制  前端控制器
 * </p>
 *
 * @author liliping
 * @since 2019-05-23
 */
@Controller
@Slf4j
@RequestMapping("/app/couponControl")
public class TbCouponControlController extends BaseController {
    @Autowired
    private ITbCouponControlService controlService;

    @GetMapping("/index")
    String index(Model model){
        return "/app/couponcontrol/couponcontrol_list";
    }

    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        List<TbCouponControl> list = controlService.queryList(query);
        int total = controlService.count(query);
        PageUtils pageUtils = new PageUtils(list, total);
        return pageUtils;
    }

    @GetMapping("/edit/{couponControlId}")
    String edit(@PathVariable("couponControlId") Integer couponControlId, Model model){
        model.addAttribute("couponControl",controlService.getDtl(couponControlId));
        return "/app/couponcontrol/couponcontrol_edit";
    }

    @ResponseBody
    @PostMapping("/update")
    public R update(TbCouponControl couponControl, HttpServletRequest request){
        couponControl.setUpdateUserId(getUserId());
        int result = controlService.update(couponControl);
        return R.ok();
    }



	
}
